<?php
// include project configuration
include(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

// symfony bootstraping
require_once($sf_symfony_lib_dir.'/util/sfCore.class.php');
sfCore::bootstrap($sf_symfony_lib_dir, $sf_symfony_data_dir);

define('SITE_URL','http://tangco.my.cn/');
define('SNS_URL',SITE_URL.'sns/index.php');
define('SNS_ROOT',SF_ROOT_DIR.DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR.'sns'.DIRECTORY_SEPARATOR);

include_once(SNS_ROOT.'common.php');
include_once(SNS_ROOT.'uc_client/client.php');
include_once(SNS_ROOT.'config.php');
include_once(SNS_ROOT.'data/data_config.php');
include_once(SNS_ROOT.'data'.DIRECTORY_SEPARATOR.'data_usergroup.php');
global $_SGLOBAL;

if(getLoginId()) {
	define('LOGINFLAG',1);
	setcookie('userid',getLoginId(),time()+60*60,'/');
	setcookie('username',getLoginName(),time()+60*60,'/');
}else{
	define('LOGINFLAG',0);
	setcookie('userid','',time()-60*60,'/');
	setcookie('username','',time()-60*60,'/');
}

function getNewActions($num=null){
	global $_SGLOBAL;
	$sql = "select id, uid, username, subject, type, type_company, p, c, area,
	eventtype, start_time, end_time, join_num, interest_num, dateline, picture, privite from 
	".tname("app_action"). ' limit 0,'.$num;
	$query = $_SGLOBAL['db']->query( $sql );
	$data = array();
	while($value = $_SGLOBAL['db']->fetch_array( $query )){
		$value['url'] = SITE_URL.'sns/action.php?ac=show&id='.$value['id'];
		$data[] = $value;
	}
	return  $data;
}

function getUserById($uid){
	global $_SGLOBAL;
	$sql = "SELECT * FROM ".tname('space')." where uid=$uid LIMIT 0,1";
	$query = $_SGLOBAL['db']->query($sql);
	$user = $_SGLOBAL['db']->fetch_array($query);
	if(!empty($user)){
		$user['grouptitle'] = $_SGLOBAL['usergroup'][$user['groupid']]['grouptitle'];
		return $user;
	}else{
		return false;
	}
}

function addFriend($uid,$uName,$fUid=1){
	$friend = getspace($fId);
	inserttable('friend', array('uid'=>$uid, 'fuid'=>$fId, 'fusername'=>addslashes($friend['username']), 'status'=>1, 'gid'=>$gid), 0, true);
	inserttable('friend', array('uid'=>$fId, 'fuid'=>$uid, 'fusername'=>$uName, 'status'=>1, 'gid'=>$gid), 0, true);
}

function getHotDiary($num=10){
	global $_SGLOBAL;
	$bloglist = array();
	$sql = "SELECT blogid,subject,uid,username FROM ".tname('blog')." WHERE friend='0' AND dateline>'$wheretime' ORDER BY replynum DESC LIMIT 0,$num";
	$query = $_SGLOBAL['db']->query($sql);
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$bloglist[] = $value;
	}
	return $bloglist;
}

function getLoginId(){
	global $_SGLOBAL;
	if((int)$_SGLOBAL['session']['uid']>0){
		return (int)$_SGLOBAL['session']['uid'];
	}else{
		return false;
	}
}

function getLoginName(){
	global $_SGLOBAL;
	if($_SGLOBAL['session']['username']!=''){
		return $_SGLOBAL['session']['username'];
	}else{
		return false;
	}
}

function getLoginSession(){
	global $_SGLOBAL;
	return $_SGLOBAL['session'];
}